package com.lc.ibps.platform.rest.org;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lc.ibps.api.org.service.IPartyEmployeeMgrService;
import com.lc.ibps.base.core.util.AppUtil;
import com.lc.ibps.base.web.context.ContextUtil;
import com.lc.ibps.cloud.entity.APIResult;
import com.lc.ibps.web.controller.BaseApiController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONObject;

/**
 * 用户操作服务接口类
 *
 * <pre> 
 * 构建组：ibps-platform-webapi
 * 作者：zhongjh
 * 邮箱：zjh20140614@163.com
 * 日期：2018年8月3日-下午2:27:24
 * 版权：广州流辰信息技术有限公司版权所有
 * </pre>
 */

@RequestMapping(value="/api/webapi/userMgrService")
@Api(value = "/userMgrService",tags="用户管理-用户操作服务")
@RestController("userMgrRest")
public class UserMgrController extends BaseApiController {

	private IPartyEmployeeMgrService employeeMgrService;
	
	public UserMgrController() {
		employeeMgrService = AppUtil.getBean(IPartyEmployeeMgrService.class);
	}
	
	@ApiOperation(value = "修改密码", notes = "修改密码")
	@RequestMapping(value="/changePassword", method = RequestMethod.POST)
	public APIResult<String> changePassword(
			@ApiParam(name = "isReset", value = "是否重置", required=false, defaultValue="0")
			@RequestParam(name = "isReset", required = false, defaultValue="0") int isReset,
			@ApiParam(name = "primitivePassword", value = "原始密码", required=true)
			@RequestParam(name = "primitivePassword", required = true) String primitivePassword,
			@ApiParam(name = "newPassword", value = "新密码", required=true)
			@RequestParam(name = "newPassword", required = true) String newPassword){
		APIResult<String> result = new APIResult<>();
		
		JSONObject jsonObject = new JSONObject();
		jsonObject.accumulate("isReset", isReset);
		jsonObject.accumulate("primitivePassword", primitivePassword);
		jsonObject.accumulate("newPassword", newPassword);
		String userId = ContextUtil.getCurrentUserId();
		jsonObject.accumulate("id", userId);
		
		try {
			employeeMgrService.updatePasswd4Employee(jsonObject.toString());
			result.setMessage("修改密码成功");
		} catch (Exception e) {
			result = getExceptionResult(result, ERROR, "修改密码失败!", e);
		}
		return result;
	}
}
